/*
* @Author: dengjiayao
* @Date:   2017-12-19 09:32:38
 * @Last Modified by: songwh
 * @Last Modified time: 2018-08-07 11:16:01
*/

import Vue from 'vue'

const SUCCESS = 1000000
const API_ROOT = server.root + '/newmanage/factor'
/**
 * 列表
 */
const keyEventsListResource = Vue.resource(API_ROOT + '/keyEventsList')
export const keyEventsList = ({ dispatch }, params) => {
  return keyEventsListResource.get(params).then(res => {
    if (+res.data.code === SUCCESS) {
      dispatch('INVITE_LIST_FRESH', 0)
      return Promise.resolve(res.data.data)
    }
    return Promise.reject(res.data)
  })
}
/**
 * 事件类型列表 
 */
const eventKpiListResource = Vue.resource(API_ROOT + '/eventKpiList')
export const eventKpiList = ({ dispatch }, params) => {
  return eventKpiListResource.get(params).then(res => {
    if (+res.data.code === SUCCESS) {
      return Promise.resolve(res.data.data)
    }
    return Promise.reject(res.data)
  })
}
/**
 * 查询
 */
const searchSecurityResource = Vue.resource(API_ROOT + '/searchSecurity')
export const searchSecurity = ({ dispatch }, params) => {
  return searchSecurityResource.get(params).then(res => {
    if (+res.data.code === SUCCESS) {
      return Promise.resolve(res.data.data)
    }
    return Promise.reject(res.data)
  })
}
/**
 * 新增
 */
const addKeyEventsResource = Vue.resource(API_ROOT + '/addKeyEvents',{}, {}, {emulateJSON: false})
export const addKeyEvents = ({ dispatch }, params) => {
  return addKeyEventsResource.save(params).then(res => {
    if (+res.data.code === SUCCESS) {
      dispatch('INVITE_LIST_FRESH', 1)
      return Promise.resolve(res.data.data)
    }
    return Promise.reject(res.data)
  })
}
/**
 * 编辑
 */
const updateKeyEventsResource = Vue.resource(API_ROOT + '/updateKeyEvents',{}, {}, {emulateJSON: false})
export const updateKeyEvents = ({ dispatch }, params) => {
  return updateKeyEventsResource.save(params).then(res => {
    if (+res.data.code === SUCCESS) {
      dispatch('INVITE_LIST_FRESH', 1)
      return Promise.resolve(res.data.data)
    }
    return Promise.reject(res.data)
  })
}
/**
 * 审核通过，驳回
 */
const updateKeyEventsStatusResource = Vue.resource(API_ROOT + '/updateStatus')
export const updateKeyEventsStatus = ({ dispatch }, params) => {
  return updateKeyEventsStatusResource.save(params).then(res => {
    if (+res.data.code === SUCCESS) {
      dispatch('INVITE_LIST_FRESH', 1)
      return Promise.resolve(res.data.data)
    }
    return Promise.reject(res.data)
  })
}
/**
 * dependValueDescList
 */
const dependValueDescListResource = Vue.resource(API_ROOT + '/dependValueDescList')
export const dependValueDescList = ({ dispatch }, params) => {
  return dependValueDescListResource.get(params).then(res => {
    if (+res.data.code === SUCCESS) {
      return Promise.resolve(res.data.data)
    }
    return Promise.reject(res.data)
  })
}